package com.twb.system.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.twb.system.common.SystemGlobal;
import com.twb.system.entity.twbDataDic.TwbDataDic;

import cn.afterturn.easypoi.handler.inter.IExcelDictHandler;

/** 
 * @ClassName ExcelDataDicHandlerImpl 
 * @Description 字典转换类
 * @author DSY
 * @date 2021年2月2日 下午2:29:05 
 */ 
public class ExcelDataDicHandlerImpl implements IExcelDictHandler {

    /**
     * 返回字典所有值
     * key: dictKey
     *
     * @param dict 字典Key
     * @return
     */
    @SuppressWarnings("rawtypes")
	@Override
    public List<Map> getList(String dict) {
    	List<TwbDataDic> dataDic = SystemGlobal.dataDic(dict);
    	if(dataDic.isEmpty()) {
    		return null;
    	}
    	 List<Map> list = new ArrayList<>();
    	for (TwbDataDic twbDataDic : dataDic) {
    		Map<String, String> dictMap = new HashMap<>();
            dictMap.put("dictKey", twbDataDic.getDataName());
            dictMap.put("dictValue", twbDataDic.getDataValue());
            list.add(dictMap);
		}
        return list;
    }

    @Override
    public String toName(String dict, Object obj, String name, Object value) {
    	
        return SystemGlobal.dataName(dict, value.toString());
    }

    @Override
    public String toValue(String dict, Object obj, String name, Object value) {
        return SystemGlobal.dataValue(dict, name);
    }
}